<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:s="http://jboss.org/schema/seam/taglib"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:richext="http://java.sun.com/jsf/composite/richext"
  template="../WEB-INF/template/template_2x.xhtml">

  <ui:define name="page_title">#{msgs['jsf.ManageSearch']}</ui:define>
  <ui:define name="center_content">
    <h:form id="form">
      <s:token allowMultiplePosts="true"/>
      <a4j:region>

        <a4j:outputPanel id="actions">
          <a4j:outputPanel
            rendered="#{reindexAction.canceled || !reindexAction.inProgress}">
            <rich:dataTable id="classList" rows="#{reindexAction.classes.size}"
              value="#{reindexAction.classes.toArray()}" var="clazz"
              render="actions">
              <rich:column width="auto" styleClass="centered" id="col">
                <f:facet
                  name="header">#{msgs['jsf.manageSearch.AllActions']}</f:facet>
                <h:selectBooleanCheckbox value="#{clazz.selectAll}">
                  <a4j:ajax event="click" render="actions" execute="@this"/>
                </h:selectBooleanCheckbox>
              </rich:column>
              <rich:column width="270px">
                <f:facet
                  name="header">#{msgs['jsf.manageSearch.Table']}</f:facet>
                <f:facet
                  name="footer">#{msgs['jsf.manageSearch.AllTables']}</f:facet>
                <h:outputText value="#{clazz.className}"/>
              </rich:column>
              <rich:column width="auto" styleClass="centered"
                footerClass="centered">
                <f:facet
                  name="header">#{msgs['jsf.manageSearch.purge']}</f:facet>
                <f:facet name="footer">
                  <h:selectBooleanCheckbox value="#{reindexAction.purgeAll}">
                    <a4j:ajax event="click" render="actions" execute="@this"/>
                  </h:selectBooleanCheckbox>
                </f:facet>
                <rich:tooltip showDelay="800" styleClass="leftalign">
                  <p>#{msgs['jsf.manageSearch.purge.Description']}</p>

                  <p>#{msgs['jsf.manageSearch.purge.ObsoletesOccupyDiskSpace']}</p>

                  <p>#{msgs['jsf.manageSearch.purge.RemoveByRunningOptimize']}</p>
                </rich:tooltip>
                <h:selectBooleanCheckbox value="#{clazz.purge}" execute="@this">
                  <a4j:ajax event="click" render="actions" execute="@this"/>
                </h:selectBooleanCheckbox>
              </rich:column>
              <rich:column width="auto" styleClass="centered"
                footerClass="centered">
                <f:facet
                  name="header">#{msgs['jsf.manageSearch.reindex']}</f:facet>
                <f:facet name="footer">
                  <h:selectBooleanCheckbox value="#{reindexAction.reindexAll}" id="reindexAllChk">
                    <a4j:ajax event="click" render="actions" execute="@this"/>
                  </h:selectBooleanCheckbox>
                </f:facet>
                <rich:tooltip showDelay="800" styleClass="leftalign">
                  <p>#{msgs['jsf.manageSearch.reindex.Description']}</p>

                  <p>#{msgs['jsf.manageSearch.reindex.OnlyWhenOutOfDate']}</p>

                  <p>#{msgs['jsf.manageSearch.reindex.AllRowsWillBeReindexed']}</p>

                  <p>#{msgs['jsf.manageSearch.reindex.IndexedRowsWillBeUpdated']}</p>

                  <p>
                    <em>#{msgs['jsf.manageSearch.reindex.TimeAndMemoryWarning']}</em>
                  </p>

                  <p>
                    <em>#{msgs['jsf.manageSearch.reindex.RunDuringOffPeak']}</em>
                  </p>
                </rich:tooltip>
                <h:selectBooleanCheckbox value="#{clazz.reindex}">
                  <a4j:ajax event="click" render="actions" execute="@this"/>
                </h:selectBooleanCheckbox>
              </rich:column>
              <rich:column width="auto" styleClass="centered"
                footerClass="centered">
                <f:facet
                  name="header">#{msgs['jsf.manageSearch.optimize']}</f:facet>
                <f:facet name="footer">
                  <h:selectBooleanCheckbox value="#{reindexAction.optimizeAll}">
                    <a4j:ajax event="click" render="actions" execute="@this"/>
                  </h:selectBooleanCheckbox>
                </f:facet>
                <rich:tooltip showDelay="800" styleClass="leftalign">
                  <p>#{msgs['jsf.manageSearch.optimize.Description']}</p>

                  <p>#{msgs['jsf.manageSearch.optimize.RemovesObsoleteEntries']}</p>

                  <p>#{msgs['jsf.manageSearch.optimize.WillNotInfluenceIndexTime']}</p>

                  <p>
                    <em>#{msgs['jsf.manageSearch.optimize.TempFileWarning']}</em>
                  </p>
                </rich:tooltip>
                <h:selectBooleanCheckbox value="#{clazz.optimize}">
                  <a4j:ajax event="click" render="actions" execute="@this"/>
                </h:selectBooleanCheckbox>
              </rich:column>
            </rich:dataTable>

            <br/>

            <a4j:commandButton id="selectNone"
              value="#{msgs['jsf.ManageSearch.SelectNone']}"
              action="#{reindexAction.selectAll(false)}"
              render="actions"/>
            <a4j:commandButton id="selectAll"
              value="#{msgs['jsf.ManageSearch.SelectAll']}"
              action="#{reindexAction.selectAll(true)}"
              render="actions"/>
            <a4j:commandButton id="reindex"
              value="#{msgs['jsf.ManageSearch.PerformSelectedActions']}"
              action="#{reindexAction.reindexDatabase}"
              render="actions,progress"/>
          </a4j:outputPanel>
        </a4j:outputPanel>

        <a4j:outputPanel id="progress">
          <h2>#{msgs['jsf.ManageSearch.CurrentProgress']}</h2>
          <s:fragment rendered="#{!reindexAction.inProgress}">
            <p id="noOperationsRunning"><h:outputText escape="false"
                value="#{msgs['jsf.ManageSearch.NoOperationsRunning']}" /></p>
          </s:fragment>
          <s:fragment rendered="#{reindexAction.reindexedSinceServerRestart and !reindexAction.inProgress and !reindexAction.canceled and !reindexAction.error}">
            <p id="completed"><h:outputText value="#{msgs.format(
              'jsf.ManageSearch.Completed', reindexAction.elapsedTime)}" /></p>
          </s:fragment>
          <s:fragment rendered="#{reindexAction.canceled}">
            <p id="aborted"><h:outputText escape="false" value="#{msgs.format(
              'jsf.ManageSearch.Aborted', reindexAction.elapsedTime)}" /></p>
          </s:fragment>
          <s:fragment rendered="#{reindexAction.error}">
            <p><h:outputText escape="false" value="#{msgs['jsf.manageSearch.ErrorMessage']}" /></p>
            <p><h:outputText escape="false" value="#{msgs['jsf.manageSearch.PleaseReindex']}" /></p>
          </s:fragment>

          <a4j:outputPanel>
            <!-- Using a js function to rerender as reRenderAfterComplete is not working properly -->
            <a4j:jsFunction name="reRenderAfterReindex"
              render="progress,actions"/>
            <rich:progressBar id="reindexProgressBar"
              value="#{reindexAction.reindexProgress}"
              interval="1000"
              label="#{msgs.format('jsf.manageSearch.ProgressMessage',
                reindexAction.reindexProgress, reindexAction.reindexCount)}"
              minValue="0"
              maxValue="#{reindexAction.reindexCount}"
              render="timeEstimate"
              reRenderAfterComplete="progress,actions"
              style="width: 550px;"
              rendered="#{reindexAction.inProgress}"
              enabled="#{reindexAction.inProgress}"
              oncomplete="reRenderAfterReindex()">
            </rich:progressBar>
          </a4j:outputPanel>

          <a4j:outputPanel id="timeEstimate">
            <s:fragment rendered="#{reindexAction.inProgress || reindexAction.canceled || reindexAction.error}">
              <p><h:outputText value="#{msgs.format(
                'jsf.manageSearch.CurrentTable', reindexAction.currentClass)}" /></p>
            </s:fragment>
            <s:fragment rendered="#{reindexAction.inProgress}">
                <p><h:outputText value="#{msgs.format(
                  'jsf.ManageSearch.ElapsedTime', reindexAction.elapsedTime)}" /></p>
                <p><h:outputText value="#{msgs.format(
                  'jsf.ManageSearch.RemainingTime', reindexAction.estimatedTimeRemaining)}" /></p>
            </s:fragment>
          </a4j:outputPanel>

          <a4j:commandButton id="cancel"
            value="#{msgs['jsf.ManageSearch.Abort']}"
            action="#{reindexAction.cancel}"
            rendered="#{reindexAction.inProgress and !reindexAction.canceled}"
            render="actions,progress"/>

        </a4j:outputPanel>

      </a4j:region>
    </h:form>
  </ui:define>

</ui:composition>
